using System;
using EMR.EMREditor.Src.Document;

namespace EMR.DocumentEditor
{
	public class ZYTextFlag : ZYTextElement
	{
		public ZYTextFlag()
		{
		}
		 
		public override string GetXMLName()
		{
			return ZYTextConst.c_TextFlag ;
		}

		public string Text
		{
			get{ return myAttributes.GetString( ZYTextConst.c_Text ) ;}
			set{ myAttributes.SetValue( ZYTextConst.c_Text , value ); }
		}

		public string FontName
		{
			get{ return myAttributes.GetString(ZYTextConst.c_FontName) ;}
			set
			{ 
				myAttributes.SetValue(ZYTextConst.c_FontName, value) ;
			}
		}

		public float FontSize
		{
			get
			{
				return myAttributes.GetFloat(ZYTextConst.c_FontSize );
			}
			set
			{
				myAttributes.SetValue(ZYTextConst.c_FontSize,value);
			}
		}
		public bool FontBold
		{
			get{ return myAttributes.GetBool(ZYTextConst.c_FontBold) ;}
			set{ myAttributes.SetValue(ZYTextConst.c_FontBold, value);  }
		}
		public bool FontUnderLine
		{
			get{ return myAttributes.GetBool(ZYTextConst.c_FontUnderLine) ;}
			set{ myAttributes.SetValue(ZYTextConst.c_FontUnderLine , value);  }
		}
		public bool FontItalic
		{
			get{ return myAttributes.GetBool(ZYTextConst.c_FontItalic) ;}
			set{ myAttributes.SetValue(ZYTextConst.c_FontItalic , value );  }
		}
		
		public System.Drawing.Font Font
		{
			get
			{
				return myOwnerDocument.View._CreateFont( this.FontName , this.FontSize , this.FontBold , this.FontItalic , this.FontUnderLine );
			}
			set
			{
				this.FontName = value.Name ;
				this.FontSize = value.Size ;
				this.FontItalic = value.Italic ;
				this.FontBold = value.Bold ;
				this.FontUnderLine = value.Underline ;
			}
		}
		public override bool RefreshSize()
		{
			string txt = this.Text ;
			if( txt == null || txt.Length == 0 )
				txt = "  ";
			System.Drawing.Font font = this.Font ;
			System.Drawing.SizeF size = myOwnerDocument.View.MeasureString( txt , font );
			this.Width = ( int ) size.Width + 12 ;
			this.Height = ( int ) size.Height + 4 ;
			return true;
		}
		public override bool RefreshView()
		{
			string txt = this.Text ;
			System.Drawing.Font font = this.Font ;
			System.Drawing.Rectangle rect = new System.Drawing.Rectangle( this.RealLeft , this.RealTop , this.Width , this.Height );
			myOwnerDocument.View.DrawString( txt , font , System.Drawing.SystemColors.ControlText , rect.X , rect.Y );
			return true;
		}
		public override string ToEMRString()
		{
			return this.Text ;
		}

	}
}